package net.zhuike.novel.app.ui.utils;

import android.os.PowerManager;

import java.lang.reflect.Method;

/**
 * Created by admin on 2017/12/27.
 */

public class CoolEngine {
    private boolean FOREGROUND;
    private volatile static CoolEngine INSTANCE;

    public static CoolEngine getInstance(){
        if (INSTANCE == null) {
            synchronized (CoolEngine.class) {
                if (INSTANCE == null) {//懒加载方式
                    INSTANCE = new CoolEngine();
                }
            }
        }
        return INSTANCE;
    }

    /**
     *   前后台进程切换的代理方法
     **/
    public synchronized void setFOREGROUND(boolean FOREGROUND) {
        if (false && FOREGROUND == true) {
            this.FOREGROUND = FOREGROUND;
            //TODO : 应用被唤醒，处理你的事情吧
        } else {
            this.FOREGROUND = FOREGROUND;
        }
    }

    public boolean isScreenOn(PowerManager pm) {
        boolean screenState;
        try {
            Method mReflectScreenState = PowerManager.class.getMethod("isScreenOn", new Class[]{});
            screenState = (Boolean) mReflectScreenState.invoke(pm);
        } catch (Exception e) {
            screenState = false;
        }
        return screenState;
    }
}
